﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data.Types;

namespace GirisSayfasi
{
    public partial class OgretmenDersOgretmenArama : Form
    {
        public static string Ogretmen_Tc;
        public OgretmenDersKayit anaform;

        MySqlConnection baglan = Connection.baglan;

        public OgretmenDersOgretmenArama()
        {
            InitializeComponent();
        }

        private void OgretmenDersOgretmenArama_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
            if (e.KeyCode == Keys.Enter)
            {

                lstOgretmenBilgileri.Items.Clear();

                baglan.Open();
                MySqlCommand cmd1 = new MySqlCommand("SELECT OgretmenTc, OgretmenAdi, OgretmenSoyadi FROM ogretmenlistesi Where OgretmenAdi LIKE @txtOgretmenAdi '%' AND OgretmenSoyadi LIKE @txtOgretmenSoyadi '%'", baglan);
                cmd1.Parameters.AddWithValue("@txtOgretmenAdi", txtOgretmenAdi.Text);
                cmd1.Parameters.AddWithValue("@txtOgretmenSoyadi", txtOgretmenSoyadi.Text);

                MySqlDataReader oku1 = cmd1.ExecuteReader();
                if (oku1.HasRows)
                {
                    while (oku1.Read())
                    {
                        ListViewItem lst = new ListViewItem();
                        lst.Text = oku1["OgretmenAdi"].ToString();
                        lst.SubItems.Add(oku1["OgretmenSoyadi"].ToString());
                        lst.Tag = oku1["OgretmenTc"];
                        lstOgretmenBilgileri.Items.Add(lst);

                    }

                }
                baglan.Close();
            }

        }

        private void OgretmenDersOgretmenArama_Activated(object sender, EventArgs e)
        {
            lstOgretmenBilgileri.Items.Clear();
            txtOgretmenAdi.Clear();
            txtOgretmenSoyadi.Clear();
            txtOgretmenAdi.Focus();
        }

        private void lstOgretmenBilgileri_DoubleClick(object sender, EventArgs e)
        {
            OgretmenDersKayit frm2 = (OgretmenDersKayit)Application.OpenForms["OgretmenDersKayit"];
            ///OgrenciKayit frm2 = new OgrenciKayit();
            frm2.mskOgretmenTc.Text = lstOgretmenBilgileri.SelectedItems[0].Tag.ToString();
            this.Hide();
        }
    }
}
